package com.lihao.wanandroid.ui.search

import android.os.Bundle
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.SearchView
import androidx.core.view.MenuItemCompat
import com.lihao.jetpackcore.ext.nav
import com.lihao.wanandroid.R
import com.lihao.wanandroid.app.base.BaseFragment
import com.lihao.wanandroid.app.ext.hideSoftKeyboard
import com.lihao.wanandroid.app.util.SettingUtil
import kotlinx.android.synthetic.main.fragment_search.*

class SearchFragment : BaseFragment<SearchViewModel>() {

    override fun layoutId() = R.layout.fragment_search

    override fun initView(savedInstanceState: Bundle?) {
        setHasOptionsMenu(true)
        initTitle(isShowBack = true){
            hideSoftKeyboard(requireActivity())
            nav().navigateUp()
        }
        (activity as? AppCompatActivity)?.setSupportActionBar(toolbar)
    }

    override fun lazyLoadData() {

    }

    override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
        super.onCreateOptionsMenu(menu, inflater)
        inflater.inflate(R.menu.search_menu, menu)
        val searchView = menu.findItem(R.id.item_search).actionView as SearchView
        searchView.let {
            it.findViewById<View>(R.id.search_plate).setBackgroundColor(
                SettingUtil.getColor(
                    requireContext(),
                    android.R.color.transparent
                )
            )
            it.onActionViewExpanded()
            it.queryHint = "搜索文章"
        }
    }
}